﻿using System;
using System.Xml.Serialization;
using WhiteFlow.Wpf.Common.Mvvm.Model;

namespace WhiteFlow.DevTrackingTool.UI.Models.Cache
{
    [Serializable]
    public class RecentWorksheet : NotifyPropertyChangedBase
    {
        #region Constants

        /// <summary>
        /// The Path property name.
        /// </summary>
        public const string PathPropertyName = "Path";

        /// <summary>
        /// The FileName property name.
        /// </summary>
        public const string FileNamePropertyName = "FileName";

        #endregion
        
        #region Fields

        private string path;

        private string fileName;

        #endregion

        #region Properties

        [XmlAttribute(AttributeName = PathPropertyName)]
        public string Path
        {
            get { return path; }
            set
            {
                path = value;
                OnPropertyChanged(PathPropertyName);
            }
        }

        [XmlAttribute(AttributeName = FileNamePropertyName)]
        public string FileName
        {
            get { return fileName; }
            set
            {
                fileName = value;
                OnPropertyChanged(FileNamePropertyName);
            }
        }

        [XmlIgnore]
        public string LastFolderInPath
        {
            get { return new System.IO.DirectoryInfo(FullPath).Name; }
        }

        [XmlIgnore]
        public string FullPath
        {
            get { return System.IO.Path.Combine(Path, FileName); }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="RecentWorksheet"/> class.
        /// </summary>
        /// <remarks>
        /// This parameterless contructor is needed by deserialization.
        /// </remarks>
        public RecentWorksheet() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="RecentWorksheet"/> class.
        /// </summary>
        /// <param name="worksheetFullPath">The worksheet's full path.</param>
        public RecentWorksheet(string worksheetFullPath)
        {
            Path = System.IO.Path.GetDirectoryName(worksheetFullPath);
            FileName = System.IO.Path.GetFileName(worksheetFullPath);
        }

        #endregion
    }
}